package util

import "sync"

type Set struct {
	data map[string]struct{}
	sw   sync.RWMutex
}

func NewSet() *Set {
	return &Set{
		data: make(map[string]struct{}),
	}
}

func (s *Set) Contains(value string) bool {
	_, ok := s.data[value]
	return ok
}

func (s *Set) Add(value string) {
	s.sw.Lock()
	defer s.sw.Unlock()
	s.data[value] = struct{}{}
}

func (s *Set) AddAll(sArr ...string) {
	s.sw.Lock()
	defer s.sw.Unlock()
	for _, k := range sArr {
		s.data[k] = struct{}{}
	}
}

func (s *Set) Remove(value string) {
	s.sw.Lock()
	defer s.sw.Unlock()
	delete(s.data, value)
}

func (s *Set) RemoveAll(sArr ...string) {
	s.sw.Lock()
	defer s.sw.Unlock()
	for _, k := range sArr {
		delete(s.data, k)
	}
}
